package com.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.*;
import com.pojo.*;
import com.service.SiteService;
import com.vo.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SiteServiceImpl implements SiteService {
    @Resource//巡查项目mapper
    private SiteMapper siteMapper;

    @Resource//巡查点mapper
    private SitepointMapper sitepointMapper;

    @Resource//巡查路线mapper
    private SiterouteMapper siterouteMapper;

    @Resource//巡查项目题目mapper
    private SitetopicMapper sitetopicMapper;

    @Resource//巡查计划题目mapper
    private SiteprojectMapper siteprojectMapper;

    @Resource//巡查任务mapper
    private SitequestMapper sitequestMapper;

    @Resource//员工mapper
    private UserMapper userMapper;

    @Resource//巡查明细mapperids
    private SiteidsMapping siteidsMapping;

    @Resource//报修repairs
    private RepairsMapper repairsMapping;

    @Resource//消息通知repairs
    private NoticeMapper noticeMapper;

    @Override
    public PageInfo<Site> selectAllSite(SiteVo siteVo) {
        PageHelper.startPage(siteVo.getPage(),siteVo.getLimit());
        List<Site> sites = siteMapper.selectAllSite(siteVo);
        PageInfo<Site> sitePageInfo = new PageInfo<>(sites);
        return sitePageInfo;
    }
    @Override
    public List<Site> selectAllSite2() {
        List<Site> sites = siteMapper.selectAllSite2();
        return sites;
    }

    @Override
    public void deletebyid(Integer id) {
        siteMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void updateByPrimaryKey(Site site) {
        siteMapper.updateByPrimaryKeySelective(site);
    }

    @Override
    public void addSite(Site site) {
        siteMapper.insertSelective(site);
    }

    @Override
    public Integer selectsitebyid(Integer id) {
        Integer selectsitebyid = siteMapper.selectsitebyid(id);
        return selectsitebyid;
    }



    @Override
    public PageInfo<Sitepoint> selectAllSitepoint(SitePointVo sitePointVo) {
        PageHelper.startPage(sitePointVo.getPage(),sitePointVo.getLimit());
        List<Sitepoint> sitepointslist = sitepointMapper.selectAllSitePoint(sitePointVo);
        PageInfo<Sitepoint> sitepointPageInfo = new PageInfo<>(sitepointslist);
        return sitepointPageInfo;
    }

    @Override
    public void deleteSitePointbyid(Integer id) {
        sitepointMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void addSitepoint(Sitepoint sitepoint) {
        sitepointMapper.insertSelective(sitepoint);
    }

    @Override
    public void updateSitepoint(Sitepoint sitepoint) {
        sitepointMapper.updateByPrimaryKeySelective(sitepoint);
    }




    @Override
    public PageInfo<Siteroute> selectAllSiteRoute(SiterouteVo siterouteVo) {
        PageHelper.startPage(siterouteVo.getPage(),siterouteVo.getLimit());
        List<Siteroute> siteroutes = siterouteMapper.selectAllSiterout(siterouteVo);
        PageInfo<Siteroute> sitePageInfo = new PageInfo<>(siteroutes);
        return sitePageInfo;
    }
    @Override
    public List<Siteroute> selectAllSiteRoute2(Integer id) {
        List<Siteroute> siteroutes = siterouteMapper.selectAllSiterout2(id);
        return siteroutes;
    }

    @Override
    public void deleteSiteRoutebyid(Integer id) {
        siterouteMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void addSiteRoute(Siteroute siteroute) {
        siterouteMapper.insertSelective(siteroute);
    }

    @Override
    public void updateSiteRoute(Siteroute siteroute) {
        siterouteMapper.updateByPrimaryKeySelective(siteroute);
    }




    @Override
    public PageInfo<Sitetopic> selectAllSitetopic(SiteTopicVo siteTopicVo) {
        PageHelper.startPage(siteTopicVo.getPage(),siteTopicVo.getLimit());
        List<Sitetopic> sitetopics = sitetopicMapper.selectAllSitetopic(siteTopicVo);
        PageInfo<Sitetopic> sitePageInfo = new PageInfo<>(sitetopics);
        return sitePageInfo;
    }

    @Override
    public void deleteSiteTopicbyid(Integer id) {
        sitetopicMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void addSiteTopic(Sitetopic sitetopic) {
        sitetopicMapper.insertSelective(sitetopic);
    }

    @Override
    public void updateSiteTopic(Sitetopic sitetopic) {
        sitetopicMapper.updateByPrimaryKeySelective(sitetopic);
    }




    @Override
    public PageInfo<Sitepoint> selectAllSitepoint2(SitePointTwoVo sitePointTwoVo) {
        PageHelper.startPage(sitePointTwoVo.getPage(),sitePointTwoVo.getLimit());
        List<Sitepoint> sitepoints = sitepointMapper.selectAllSitePoint2(sitePointTwoVo);
        PageInfo<Sitepoint> sitePageInfo = new PageInfo<>(sitepoints);
        return sitePageInfo;
    }

    @Override
    public PageInfo<Sitepoint> selectAllSitepoint3(SitePointTwoVo sitePointTwoVo) {
        PageHelper.startPage(sitePointTwoVo.getPage(),sitePointTwoVo.getLimit());
        List<Sitepoint> sitepoints = sitepointMapper.selectAllSitePoint3(sitePointTwoVo);
        PageInfo<Sitepoint> sitePageInfo = new PageInfo<>(sitepoints);
        return sitePageInfo;
    }

    @Override
    public List<Sitepoint> selectsitepoint() {
        List<Sitepoint> selectsitepoint = sitepointMapper.selectsitepoint();
        return selectsitepoint;
    }


    @Override
    public void updateSitepoint2(Sitepoint sitepoint) {
        sitepointMapper.updateByPrimaryKeySelective(sitepoint);
    }



    @Override
    public PageInfo<Siteproject> selectAllSiteProject(SiteProjectVo siteProjectVo) {
        PageHelper.startPage(siteProjectVo.getPage(),siteProjectVo.getLimit());
        List<Siteproject> siteprojects = siteprojectMapper.selectAllSiteproject(siteProjectVo);
        PageInfo<Siteproject> sitePageInfo = new PageInfo<>(siteprojects);
        return sitePageInfo;
    }

    @Override
    public void deleteSiteProject(Integer id) {
        siteprojectMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Integer selelectSiteProjectbyid(Integer id) {
        Integer integer = siteprojectMapper.selelectSiteProjectbyid(id);
        return integer;
    }

    @Override
    public void updateSiteProjectbyid(Siteproject siteproject) {
        siteprojectMapper.updateByPrimaryKeySelective(siteproject);
    }

    @Override
    public void addSiteProject(Siteproject siteproject) {
        siteprojectMapper.insertSelective(siteproject);
    }

    @Override
    public List<User> selectAllUser(Integer id) {
        List<User> users = userMapper.selectAllUser(id);
        return users;
    }

    @Override
    public void updateSiteProject(Siteproject siteproject) {
        siteprojectMapper.updateByPrimaryKeySelective(siteproject);
    }

    @Override
    public List<User> selectUsermcA(Integer id,Integer ids) {
        List<User> users = userMapper.selectUsermcB( id , ids );
        return users;
    }



    @Override
    public PageInfo<Sitequest> selectAllSiteQuest(SiteQuestVo siteQuestVo) {
        PageHelper.startPage(siteQuestVo.getPage(),siteQuestVo.getLimit());
        List<Sitequest> sitequests = sitequestMapper.selectAllSiteQuest(siteQuestVo);
        PageInfo<Sitequest> sitePageInfo = new PageInfo<>(sitequests);
        return sitePageInfo;
    }

    @Override
    public void deleteSiteQuest(Integer id) {
        sitequestMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Integer selectsitequestdeleteid(Integer id) {
        Integer selectdeletequestid = sitequestMapper.selectdeletequestid(id);
        return selectdeletequestid;
    }

    @Override
    public void addSiteQuest(Sitequest sitequest) {
        sitequestMapper.insertSelective(sitequest);
    }

    @Override
    public void updateSiteQuest(Sitequest sitequest) {
        sitequestMapper.updateByPrimaryKeySelective(sitequest);
    }

    @Override
    public List<User> selectSiteQuestUser(SiteQuestUserVo siteQuestUserVo) {
        userMapper.selectSiteQuestUserA(siteQuestUserVo);
        return null;
    }

    @Override
    public Integer selectquestidbyprojectidtoupdate(Integer id) {
        Integer selectid = sitequestMapper.selectid(id);
        if (selectid == 0 && selectid==null){
            return 0;
        }else {
            return selectid;
        }
    }

    @Override
    public List<Sitepoint> selectSiteQuestxiangqing(Integer id) {
        int selectquestid = sitequestMapper.selectquestid(id);
        int selectrouteid = sitequestMapper.selectrouteid(selectquestid);
        List<Sitepoint> selectpointbyrouteid = sitequestMapper.selectpointbyrouteid(selectrouteid);
        return selectpointbyrouteid;
    }

    @Override
    public Sitepoint selectpointbyid(Integer id) {
        Sitepoint selectpointbyid = sitequestMapper.selectpointbyid(id);
        return selectpointbyid;
    }


//明细



    @Override
    public void addsiteids(Siteids siteids) {
        siteidsMapping.insertSelective(siteids);
    }

    @Override
    public List<Integer> selectpointidbyrouteid(Integer id) {
        List<Integer> selectpointidbyrouteid = siteidsMapping.selectpointidbyrouteid(id);
        return selectpointidbyrouteid;
    }


    @Override
    public PageInfo<Siteids> selectsiteids(SiteDetailVo detailVo) {
        PageHelper.startPage(detailVo.getPage(),detailVo.getLimit());
        List<Siteids> selecrsiteids = siteidsMapping.selecrsiteids();
        PageInfo<Siteids> sitePageInfo = new PageInfo<>(selecrsiteids);
        return sitePageInfo;
    }

    @Override
    public void addbaoxiu(Repairs repairs) {
        repairsMapping.insertSelective(repairs);
    }

    @Override
    public List<Integer> selectrenwuid(Integer id) {
        Integer integer = sitequestMapper.selectquestidbyidTwo(id);
        Integer selectquestidbyidthree = sitequestMapper.selectquestidbyidthree(integer);
        List<Integer> selectlistidsbyid = sitequestMapper.selectlistidsbyid(selectquestidbyidthree);
        return selectlistidsbyid;
    }

    @Override
    public Integer selectpointstate(Integer id) {
        Integer selectpointstate = sitequestMapper.selectpointstate(id);
        return selectpointstate;
    }

    @Override
    public void selectmingxiidbyid(Integer id) {
        List<Integer> selectminxiidbyid = siteidsMapping.selectminxiidbyid(id);
        for (Integer integer : selectminxiidbyid) {
            siteidsMapping.deleteByPrimaryKey(integer);
        }
    }

    @Override
    public List<Integer> selectpointid(Integer id) {
        Integer selectquestidbyidthree = sitequestMapper.selectquestidbyidthree(id);
        List<Integer> selectlistidsbyid = sitequestMapper.selectlistidsbyid(selectquestidbyidthree);
        return selectlistidsbyid;
    }

    @Override
    public Integer selectroutestatebyid(Integer id) {
        Integer selectroutestatebyid = siterouteMapper.selectroutestatebyid(id);
        return selectroutestatebyid;
    }

    @Override
    public List<Integer> selectpointidsaaabbb(Integer id) {
        List<Integer> selectlistidsbyid = sitequestMapper.selectlistidsbyid(id);
        return selectlistidsbyid;
    }

    @Override
    public void selectmingxiidbyquestid(Integer id) {
        Integer selectprojectidbyquestid = siteidsMapping.selectprojectidbyquestid(id);
        List<Integer> selectminxiidbyid = siteidsMapping.selectminxiidbyid(selectprojectidbyquestid);
        for (Integer integer : selectminxiidbyid) {
            siteidsMapping.deleteByPrimaryKey(integer);
        }
    }

    @Override
    public List<Repairs> selectrepairs() {

        return null;
    }


    @Override
    public void deleteselectmingxiids() {
        List<Integer> selectmingxiids = siteidsMapping.selectmingxiids();
        for (Integer selectmingxiid : selectmingxiids) {
            siteidsMapping.deleteByPrimaryKey(selectmingxiid);
        }
    }

    @Override
    public List<Integer> selectprojectids() {
        List<Integer> selectprojectids = siteidsMapping.selectprojectids();
        return selectprojectids;
    }

    @Override
    public Siteproject selectsiteprojectbyidsthree(Integer id) {
        Siteproject selectprojectbyidthree = siteidsMapping.selectprojectbyidthree(id);
        return selectprojectbyidthree;
    }

    @Override
    public PageInfo<Notice> selectnotice(NoticeVo noticeVo) {
        PageHelper.startPage(noticeVo.getPage(),noticeVo.getLimit());
        List<Notice> selectnotice = noticeMapper.selectnotice(noticeVo);
        PageInfo<Notice> sitePageInfo = new PageInfo<>(selectnotice);
        return sitePageInfo;
    }


}













